package javabase.schoolwork.day6_15;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author fance
 * @date 18-6-16 上午8:59
 */
public class HelloProxy implements IHello {
    private IHello iHello;
    private long st;
    private BufferedWriter writer;
    public HelloProxy(BufferedWriter writer) {
        this.iHello = new HelloImpl();
        this.writer = writer;
    }

    @Override
    public void fun1() {
        try {

            before();
            iHello.fun1();
            writer.write(String.valueOf(after()));
            writer.write("\n");
            writer.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }



    private void before() {
        this.st = System.currentTimeMillis();
    }
    private long after() {
        return System.currentTimeMillis() - st;
    }

}
